from socf.server import discovery
from socf import conf
from socf.client import local
from socf.services.constants import *

import unittest
import os

class ConfigurationTest(unittest.TestCase):
    
    def setUp(self):
        pass
        
    def __convertServiceListToMap(self,  list):
        map = {}
        for entry in list:
            map[entry[2]] = entry[1].__str__()
        return map
        
    def testDiscoveryService(self):
        #creates configuration context
        configContext = conf.ConfigurationContext(os.path.join(os.getcwd(),  "conf"))
        #get service stub provider
        localProvider = local.LocalObjectStubProvider.createProvider(configContext, "dbus")
        #contact the discovery service
        discoveryStub = localProvider.getServiceClientStub(DISCOVERY_SERVICE_TYPE, "dbus:laf.socf/server/discoveryService")
        servicesMap = self.__convertServiceListToMap(discoveryStub.getCurrentServicesList())
        self.assert_(len(servicesMap) > 0)
        print "Services:" + str(servicesMap)


if __name__ == '__main__':
    unittest.main()

